class Node:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

class CircularLinkedList:
    def __init__(self):
        self.head = None

    def is_empty(self):
        return self.head is None

    def insert_at_head(self, val):
        """在循环链表头部插入节点"""
        new_node = Node(val)
        if self.is_empty():
            new_node.next = new_node  # 空链表时，节点自指
            self.head = new_node
            return
        # 找到尾节点
        current = self.head
        while current.next != self.head:
            current = current.next
        # 新节点指向原头节点
        new_node.next = self.head
        # 尾节点指向新节点
        current.next = new_node
        # 新节点成为头节点
        self.head = new_node

    def traverse(self):
        if self.is_empty():
            return []
        result = []
        current = self.head
        while True:
            result.append(current.val)
            current = current.next
            if current == self.head:
                break
        return result

# 测试
if __name__ == "__main__":
    cll = CircularLinkedList()
    cll.insert_at_head(3)
    cll.insert_at_head(2)
    cll.insert_at_head(1)
    print("插入头部后遍历:", cll.traverse())  # 输出: [1, 2, 3]